#include "aiDifficultyDialog.h"

#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QVBoxLayout>

AIDifficultyDialog::AIDifficultyDialog(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle("选择AI难度");
    setFixedSize(300, 200);

    QVBoxLayout *layout = new QVBoxLayout(this);

    // 标题
    QLabel *titleLabel = new QLabel("请选择AI难度级别：", this);
    titleLabel->setStyleSheet("font-size: 16px; font-weight: bold;");
    layout->addWidget(titleLabel, 0, Qt::AlignHCenter);

    // 难度选项
    m_buttonGroup = new QButtonGroup(this);

    QStringList difficulties = {"简单 (适合新手)", "中等 (标准挑战)", "困难 (大师级别)"};
    for (int i = 0; i < difficulties.size(); ++i) {
        QRadioButton *radio = new QRadioButton(difficulties[i], this);
        radio->setStyleSheet("font-size: 14px; padding: 8px;");
        m_buttonGroup->addButton(radio, i);
        layout->addWidget(radio);

        if (i == 1) radio->setChecked(true); // 默认选中中等
    }

    // 确认按钮
    QPushButton *confirmBtn = new QPushButton("开始对战", this);
    confirmBtn->setStyleSheet(
        "QPushButton {"
        "  background: #4CAF50;"
        "  color: white;"
        "  border-radius: 5px;"
        "  padding: 8px 16px;"
        "  font-size: 14px;"
        "}"
        "QPushButton:hover { background: #45a049; }"
        );

    layout->addSpacing(15);
    layout->addWidget(confirmBtn, 0, Qt::AlignHCenter);

    // 信号连接
    connect(m_buttonGroup, &QButtonGroup::idClicked,
            this, &AIDifficultyDialog::onDifficultySelected);
    connect(confirmBtn, &QPushButton::clicked, this, &QDialog::accept);
}

void AIDifficultyDialog::onDifficultySelected(int id) {
    m_difficulty = static_cast<Difficulty>(id);
}
